define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'coupons/bind/index' + location.search,
                    add_url: 'coupons/bind/add',
                    edit_url: 'coupons/bind/edit',
                    del_url: 'coupons/bind/del',
                    multi_url: 'coupons/bind/multi',
                    import_url: 'coupons/bind/import',
                    table: 'coupons_bind',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'user.nickname', title: __('User.nickname')},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'group_id', title: __('Group_id')},
                        {field: 'usergroup.name', title: __('Usergroup.name'),sortable:true},
                        {field: 'statuslist', title: __('Statuslist'), searchList: {"0":__('Statuslist 0'),"1":__('Statuslist 1')}, formatter: Table.api.formatter.normal},
                        {field: 'number', title: __('Number'), operate: 'LIKE'},
                        {field: 'userstaff.staffnumber', title: __('Userstaff.staffnumber'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
             var group_id = $("#c-group_id").val();
             if(group_id==1){
                $("#c-number-c").hide();
             }
             if(group_id==2){
                $("#c-number-c").show();
             }
             $("#c-group_id").change(function () {
                  var group_id = $("#c-group_id").val();
                 console.log(group_id);
                if (group_id ==1) {
                    $("#c-number-c").hide();
                } else {
                    $("#c-number-c").show();
                }
            });
        },
        edit: function () {
            Controller.api.bindevent();
            var group_id = $("#c-group_id").val();
             if(group_id==1){
                $("#c-number-c").hide();
             }
             if(group_id==2){
                $("#c-number-c").show();
             }
             $("#c-group_id").change(function () {
                  var group_id = $("#c-group_id").val();
                  console.log(group_id);
                if (group_id ==1) {
                    $("#c-number-c").hide();
                } else {
                    $("#c-number-c").show();
                }
            });
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});